package ym.ecrm.core.dao.systemManagement.impl;

import java.sql.SQLException;
import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.beans.factory.HierarchicalBeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.stereotype.Repository;

import ym.ecrm.core.common.util.Pager;
import ym.ecrm.core.dao.base.impl.HibernateEntityDAO;
import ym.ecrm.core.dao.systemManagement.IResourceDAO;
import ym.ecrm.core.domain.systemManagement.Resource;


@Repository
@SuppressWarnings("unchecked")
public class HibernateResourceDAO extends HibernateEntityDAO<Resource>
		implements IResourceDAO {

	
	////@Override
	public List<Resource> findResources(final int pageNumber, final int pageSize) {
		List<Resource> list = getHibernateTemplate().executeFind(
				new HibernateCallback<List<Resource>>() {

					//@Override
					public List<Resource> doInHibernate(Session session)
							throws HibernateException, SQLException {
						int fireIndex = Pager.getStartIndex(pageNumber, pageSize);
						return session.createQuery("from Resource").
							setFirstResult(fireIndex).setMaxResults(pageSize).list();
					}
					
		});
		return list;
	}

}
